<?php
/**
 * 
 * @author	ronnie  (comdeng@gmail.com)
 * @link		http://fillphp.com/
 * @date		2014-5-2 下午5:11:43
 * @file		IView.php
 * @description 
 */
namespace fillphp\view;

require_once dirname(__DIR__).'/helper/Helper.php';
abstract class View
{
	private $vars = array();
	/**
	 * @var \fillphp\page\Request
	 */
	var $request;
	
	/**
	 * 
	 * @param \fillphp\page\Request $request
	 */
	function __construct($request)
	{
		$this->request = $request;
	}
	
	/**
	 * (non-PHPdoc)
	 * @see \fillphp\view\IView::init()
	 */
	function init(array $conf = array())
	{
		if (isset($conf['helperDir'])) {
			$this->helperDir = $conf['helperDir'];
		}
		
		if (isset($conf['helperNs'])) {
			$this->helperNs = $conf['helperNs'];
		}
	}
	
	/**
	 * 对模板进行编译
	 * @param string $path
	 * @return string
	 */
	abstract function display($path);
	
	/**
	 * 设置变量
	 * @param string $key
	 * @param mixed $value
	 * @return \fillphp\view\View
	 */
	function set($key, $value)
	{
		$this->vars[$key] = $value;
		return $this;
	}
	
	/**
	 * 批量设置变量
	 * @param array $values
	 * @return \fillphp\view\View
	 */
	function setArray(array $values)
	{
		$this->vars = array_replace($this->vars, $values);
		return $this;
	}
	
	/**
	 * 获取属性
	 * @param string $name
	 */
	function __get($name)
	{
		if (isset($this->vars[$name])) {
			return $this->vars[$name];
		}
		return '';
	}
	
	/**
	 * 调用帮助器
	 * @param string $name
	 * @param array $args
	 */
	function __call($name, $args)
	{
		$helper = \fillphp\helper\Helper::getHelper($name);
		$helper->setView($this);
		return $helper;
	}
}
